<?php
C_base::Dy('c.kefu.kfbase');
class tuisong extends kfbase{
	
	var $_vpath='kefu/tuisong/';  //定义调用模板所属一级文件夹
	
	function __construct(){
		parent::__construct();
		$this->title='';
	}
	
	function shipin(){
		$this->tit ='课程管理';
		$this->type = $this->_get('type');
		for($i=0;$i<=9;$i++){
			$rrs[$i] =  C_base::M('admin.recruit')->sp_ss($i);
		}
		if(@$rrs){
			foreach ($rrs as $k=>$v){
				if($v){
					foreach ($v as $kk=>$vv){
						if($this->_get('type') == 1){//视频
							if($vv['shipin']){
								$this->rs[]=$vv;
							}	
						}elseif($this->_get('type') == 2){//文章
							if(empty($vv['shipin'])){
								$this->rs[]=$vv;
							}
						}
					}
				}
			}
		}
	}
	
	function ts_shipin(){
		$this->title = '视频';
		$this->rs['spid'] = $this->_get('id');
		$this->rs['zjid'] = $this->_get('zjid');
		$this->rs['title'] = $this->_get('title');
		$this->rs['jifen'] = $this->_get('jifen');
		$this->rs['type'] = $this->_get('type');
	}
	
	//添加视频
	function sp_c(){
		$this->_is_html = 1;
		extract($this->_post());
		if(@empty($spid)){
			exit('error');
		}
		$w = array('id'=>$spid);
		$r = C_base::M('admin.recruit')->sp_s($zjid,$w);
		if(@empty($r)){
			exit('-1');//没有视频数据
		}
		if(empty($datemin)){
			exit('-5');//推送时间不能为空
		}else{
			if(strtotime($datemin) < time()){
				exit('-2');//推送时间不能低于当前时间
			}
		}
		if(@empty($sztype)){
			exit('-3');//受众类型不能为空
		}
		$c = array('kfid'=>$_SESSION['kf_id'],'spid'=>$spid,'zjid'=>$zjid,'tstime'=>strtotime($datemin),'sz'=>$sztype,'time'=>time());
		$r = C_base::M('kefu.tuisong')->ts_c($c);
		if($r > 0){
			/* if($datemin == ''){//即时推送
				if($sztype == 1){//大学生
					$w1 = array('bytime'=>$c['time']);
				}else{//应届生
					$time = $c['time'] - 60*60*24*365;
					$w1 = array('bytime>'=>$time,'bytime<'=>$c['time']);
				}
				$rs = C_base::M('admin.recruit')->ubase_ss($w1);
				if(@$rs){
					foreach($rs as $k => $v){
						$c1 = array('spid'=>$spid,'uid'=>$v['uid'],'zjid'=>$zjid,'type'=>0,'time'=>time());
						C_base::M('admin.recruit')->tz_c($v['uid'],$c1);
						//未读推荐数+1
						$this->user_tongji(array('uid'=>$v['uid'],'ziduan'=>'tuijian','type'=>'+'));
					}
				}else{
					exit('-4');//暂无该类用户
				}
			} */
			exit('cg');
		}else{
			exit('error');
		}
	}
	
	//定时推送，每天凌晨定时执行
	function dsts(){
		$time = time();
		$lctime = mktime(0,0,0,date('m',$time),date('d',$time),date('Y',$time));
		$w = array('tstime'=>$lctime);
		$r = C_base::M('kefu.tuisong')->ts_ss($w);
		if(@$r){
			foreach($r as $k => $v){
				if(@$v){
					if($v['sz'] == 1){//大学生
						$w1 = array('bytime'=>$v['time']);
					}else{//应届生
						$time1 = $v['time'] - 60*60*24*365;
						$w1 = array('bytime>'=>$time1,'bytime<'=>$v['time']);
					}
					$rs = C_base::M('admin.recruit')->ubase_ss($w1);
					if(@$rs){
						foreach($rs as $k1 => $v1){
							$c1 = array('spid'=>$v['spid'],'uid'=>$v1['uid'],'zjid'=>$v['zjid'],'type'=>0,'time'=>time());
							C_base::M('admin.recruit')->tz_c($v1['uid'],$c1);
							//未读推荐数+1
							$this->user_tongji(array('uid'=>$v1['uid'],'ziduan'=>'tuijian','type'=>'+'));
						}
					}
				}
			}
		}
	}
	
	/**
	 * 用户数据统计
	 * $uid	用户id
	 * $ziduan	要统计的字段
	 * $type	操作。+-
	 */
	function user_tongji($post){
		extract($post);
		$w = array('uid'=>$uid);
		$pd = C_base::M('admin.recruit')->tongji_s($w);
		if($pd){
			$x = $ziduan.$type;
			$u = array($x=>1);
			C_base::M('admin.recruit')->tongji_u($w,$u);
		}else{
			$c = array('uid'=>$uid,$ziduan=>1);
			C_base::M('admin.recruit')->tongji_c($c);
		}
	}
}
/*********************************************************************文件已结束*****************************************************************/